package Classic150;

public class 盛最多水的容器 {
    /*
        首尾双指针，注意内循环的作用
     */
    public int maxArea(int[] height) {
        int maxArea = 0;
        int left = 0, right = height.length - 1;
        while (left < right) {
            int minHeight = Math.min(height[right], height[left]);
            maxArea = Math.max(maxArea, minHeight * (right - left));
            while (left < right && height[left] <= minHeight) left++;
            while (left < right && height[right] <= minHeight) right--;
        }
        return maxArea;
    }
}
